home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / linuxdoc-sgml-1.1 / sgmls-1.1 / sgmlxtrn.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  11.5 KB  |  224 lines

  1. /*    Standard Generalized Markup Language Users' Group (SGMLUG)
  2.                  SGML Parser Materials (ARCSGML 1.0)
  3.  
  4. (C) 1983-1988 Charles F. Goldfarb (assigned to IBM Corporation)
  5. (C) 1988-1991 IBM Corporation
  6.  
  7. Licensed to the SGML Users' Group for distribution under the terms of
  8. the following license:                                                       */
  9.  
  10. char license[] =
  11. "SGMLUG hereby grants to any user: (1) an irrevocable royalty-free,\n\
  12. worldwide, non-exclusive license to use, execute, reproduce, display,\n\
  13. perform and distribute copies of, and to prepare derivative works\n\
  14. based upon these materials; and (2) the right to authorize others to\n\
  15. do any of the foregoing.\n";
  16.  
  17. #include "sgmlincl.h"
  18.  
  19. /* SGMLXTRN: Storage allocation and initialization for all public variables.
  20.              Exceptions: Constants lex????? and del????? are defined in
  21.              LEX?????.C modules; constants pcb????? are defined in PCB?????.c.
  22. */
  23. int badresw = 0;              /* 1=REF_ out of context; 0=valid. */
  24. int charmode = 0;             /* >0=in #CHARS; 0=not. */
  25. int conactsw = 0;             /* 1=return saved content action 0=get new one.*/
  26. int conrefsw = 0;             /* 1=content reference att specified; 0=no. */
  27. int contersv = 0;             /* Save contersw while processing pending REF. */
  28. int contersw = 0;             /* 1=element or #CHARS out of context; 0=valid. */
  29. int datarc = 0;               /* Return code for data: DAF_ or REF_. */
  30. int delmscsw = 0;             /* 1=DELMSC must be read on return to es==0. */
  31. int didreq = 0;               /* 1=required implied tag processed; 0=no. */
  32. int dostag = 0;               /* 1=retry newetd instead of parsing; 0=parse. */
  33. int dtdsw = 0;                /* DOCTYPE declaration found: 1=yes; 0=no. */
  34. int entdatsw = 0;             /* 2=CDATA entity; 4=SDATA; 8=NDATA; 0=none. */
  35. int entpisw = 0;              /* 4=PI entity occurred; 0=not. */
  36. int eodsw = 0;                /* 1=eod found in error; 0=not yet. */
  37. int eofsw = 0;                /* 1=eof found in body of document; 0=not yet. */
  38. int es = -1;                  /* Index of current source in stack. */
  39. int etagimct = 0;             /* Implicitly ended elements left on stack. */
  40. int etagimsw = 0;             /* 1=end-tag implied by other end-tag; 0=not. */
  41. int etagmin = MINNONE;        /* Minim: NONE NULL NET DATA; implied by S/ETAG*/
  42. int etictr = 0;               /* Number of "NET enabled" tags on stack. */
  43. int etisw = 0;                /* 1=tag ended with eti; 0=did not. */
  44. int indtdsw = 0;              /* Are we in the DTD? 1=yes; 0=no. */
  45. int mslevel = 0;              /* Nesting level of marked sections. */
  46. int msplevel = 0;             /* Nested MS levels subject to special parse. */
  47. int prologsw = 1;             /* 1=in prolog; 0=not. */
  48. int pss = 0;                  /* SGMLACT: scbsgml stack level. */
  49. int sgmlsw = 0;               /* SGML declaration found: 1=yes; 0=no. */
  50. int stagmin = MINNONE;        /* Minimization: NONE, NULL tag, implied by STAG*/
  51. int tagctr = 0;               /* Tag source chars read. */
  52. int ts = -1;                  /* Index of current tag in stack. */
  53. struct parse *propcb = &pcbpro; /* Current PCB for prolog parse. */
  54. int aentctr = 0;              /* Number of ENTITY tokens in this att list. */
  55. int conact = 0;               /* Return code from content parse. */
  56. int conrefsv = 0;             /* Save conrefsw when doing implied start-tag.*/
  57. int dtdrefsw = 0;             /* External DTD? 1=yes; 0=no. */
  58. int etiswsv = 0;              /* Save etisw when processing implied start-tag.*/
  59. int grplvl = 0;               /* Current level of nested grps in model. */
  60. int idrctr = 0;               /* Number of IDREF tokens in this att list. */
  61. int mdessv = 0;               /* ES level at start of markup declaration. */
  62. int notadn = 0;               /* Position of NOTATION attribute in list. */
  63. int parmno = 0;               /* Current markup declaration parameter number. */
  64. int pexsw = 0;                /* 1=tag valid solely because of plus exception.*/
  65. int rcessv = 0;               /* ES level at start of RCDATA content. */
  66. int tagdelsw = 0;             /* 1=tag ended with delimiter; 0=no delimiter. */
  67. int tokencnt = 0;             /* Number of tokens found in attribute value. */
  68. struct entity *ecbdeflt = 0;  /* #DEFAULT ecb (NULL if no default entity). */
  69. struct etd *docetd = 0;       /* The etd for the document as a whole. */
  70. struct etd *etagreal = 0;     /* Actual or dummy etd that implied this tag. */
  71. struct etd *newetd = 0;       /* The etd for a start- or end-tag recognized. */
  72. struct etd *nextetd = 0;      /* ETD that must come next (only one choice). */
  73. struct etd *stagreal = 0;     /* Actual or dummy etd that implied this tag. */
  74. struct parse *conpcb = 0;     /* Current PCB for content parse. */
  75. UNCH *data = 0;               /* Pointer to returned data in buffer. */
  76. UNCH *mdname = 0;             /* Name of current markup declaration. */
  77. UNCH *ptcon = 0;              /* Current pointer into tbuf. */
  78. UNCH *ptpro = 0;              /* Current pointer into tbuf. */
  79. UNCH *rbufs = 0;              /* DOS file read area: start position for read. */
  80. UNCH *subdcl = 0;             /* Subject of markup declaration (e.g., GI). */
  81. int Tstart = 0;               /* Save starting token for AND group testing. */
  82. UNS conradn = 0;              /* 1=CONREF attribute in list (0=no). */
  83. UNS datalen = 0;              /* Length of returned data in buffer. */
  84. UNS entlen = 0;               /* Length of TAG or EXTERNAL entity text. */
  85. UNS idadn = 0;                /* Number of ID attribute (0 if none). */
  86. UNS noteadn = 0;              /* Number of NOTATION attribute (0 if none). */
  87. UNS reqadn = 0;               /* Num of atts with REQUIRED default (0=none). */
  88. int grplongs;              /* Number of longs for GRPCNT bitvector. */
  89.  
  90. /* Variable arrays and structures.
  91. */
  92. struct ad *al = 0;            /* Current attribute list work area. */
  93. struct dcncb *dcntab[1];      /* List of data content notation names. */
  94. struct entity *etab[ENTHASH]; /* Entity hash table. */
  95. struct etd *etdtab[ETDHASH];  /* Element type definition hash table. */
  96. struct fpi fpidf;             /* Fpi for #DEFAULT entity. */
  97. struct id *itab[IDHASH];      /* Unique identifier hash table. */
  98. struct etd **nmgrp = 0;          /* Element name group */
  99. PDCB *nnmgrp = 0;          /* Notation name group */
  100. struct restate *scbsgml = 0;  /* SGMLACT: return action state stack. */
  101. struct source *scbs = 0;      /* Stack of open sources ("SCB stack"). */
  102. struct srh *srhtab[1];        /* List of SHORTREF table headers. */
  103. struct sgmlstat ds;           /* Document statistics. */
  104. struct switches sw;           /* Parser control switches set by text proc. */
  105. struct tag *tags = 0;         /* Stack of open elements ("tag stack"). */
  106. struct thdr *gbuf = 0;        /* Buffer for creating group. */
  107. struct thdr prcon[3];         /* 0-2: Model for *DOC content. */
  108. struct thdr undechdr;         /* 0:Default model hdr for undeclared content.*/
  109. UNCH *dtype = 0;              /* Document type name. */
  110. UNCH *entbuf = 0;             /* Buffer for entity reference name. */
  111. UNCH fce[2];                  /* String form of FCE char.
  112.                                  (fce[1] must be EOS).*/
  113. /* Buffer for non-SGML character reference.*/
  114. UNCH nonchbuf[2] = { DELNONCH };
  115. UNCH *tbuf;              /* Work area for tokenization. */
  116. UNCH *lbuf = 0;              /* In tbuf: Literal parse area.*/
  117. UNCH *sysibuf = 0;          /* Buffer for system identifiers. */
  118. UNCH *pubibuf = 0;          /* Buffer for public identifiers. */
  119. UNCH *nmbuf = 0;          /* Name buffer used by mdentity. */
  120. struct mpos *savedpos;
  121.  
  122. /* Constants.
  123. */
  124. struct map dctab[] = {        /* Keywords for declared content parameter.*/
  125.      { key[KRCDATA],  MRCDATA+MPHRASE },
  126.      { key[KCDATA],   MCDATA+MPHRASE },
  127.      { key[KANY],     MANY+MCHARS+MGI },
  128.      { key[KEMPTY],   MNONE+MPHRASE },
  129.      { NULL,          0 }
  130. };
  131. struct map deftab[] = {       /* Default value keywords. */
  132.      { key[KIMPLIED],  DNULL },
  133.      { key[KREQUIRED], DREQ  },
  134.      { key[KCURRENT],  DCURR },
  135.      { key[KCONREF],   DCONR },
  136.      { key[KFIXED],    DFIXED},
  137.      { NULL,           0}
  138. };
  139. struct map dvtab[] = {        /* Declared value: keywords and type codes.*/
  140. /*                                TYPE      NUMBER   */
  141. /*   grp             ANMTGRP      Case 1 0  Grp size */
  142. /*   grp member      ANMTGRP      Case   0  Position */
  143. /*   grp             ANOTEGRP     Case 1 1  Grp size */
  144.      { key[KNOTATION], ANOTEGRP}, /* Case   1  Position */
  145.      { key[KCDATA],    ACHARS  }, /* Case   2  Always 0 */
  146.      { key[KENTITY],   AENTITY }, /* Case   3  Normal 1 */
  147.      { key[KID],       AID     }, /* Case   4  Normal 1 */
  148.      { key[KIDREF],    AIDREF  }, /* Case   5  Normal 1 */
  149.      { key[KNAME],     ANAME   }, /* Case   6  Normal 1 */
  150.      { key[KNMTOKEN],  ANMTOKE }, /* Case   7  Normal 1 */
  151.      { key[KNUMBER],   ANUMBER }, /* Case   8  Normal 1 */
  152.      { key[KNUTOKEN],  ANUTOKE }, /* Case   9  Normal 1 */
  153.      { key[KENTITIES], AENTITYS}, /* Case   A  Normal 1 */
  154.      { key[KIDREFS],   AIDREFS }, /* Case   B  # tokens */
  155.      { key[KNAMES],    ANAMES  }, /* Case   C  # tokens */
  156.      { key[KNMTOKENS], ANMTOKES}, /* Case   D  # tokens */
  157.      { key[KNUMBERS],  ANUMBERS}, /* Case   E  # tokens */
  158.      { key[KNUTOKENS], ANUTOKES}, /* Case   F  # tokens */
  159.      { NULL,           0 }         /* Case   0  ERROR    */
  160. };
  161. struct map enttab[] = {       /* Entity declaration second parameter. */
  162.      { key[KCDATA],     ESC },
  163.      { key[KSDATA],     ESX },
  164.      { key[KMS],        ESMS},
  165.      { key[KPI],        ESI },
  166.      { key[KSTARTTAG],  ESS },
  167.      { key[KENDTAG],    ESE },
  168.      { key[KMD],        ESMD},
  169.      { NULL,            0 }
  170. };
  171. struct map exttab[] = {       /* Keywords for external identifier. */
  172.      { key[KSYSTEM],    EDSYSTEM },
  173.      { key[KPUBLIC],    EDPUBLIC },
  174.      { NULL,            0 }
  175. };
  176. struct map extettab[] = {       /* Keywords for external entity type. */
  177.      { key[KCDATA],     ESNCDATA },
  178.      { key[KNDATA],     ESNNDATA },
  179.      { key[KSDATA],     ESNSDATA },
  180.      { key[KSUBDOC],    ESNSUB },
  181.      { NULL,            0 }
  182. };
  183. struct map funtab[] = {       /* Function character reference names. */
  184.      { key[KRE],       RECHAR },
  185.      { key[KRS],       RSCHAR },
  186.      { key[KSPACE],    SPCCHAR },
  187.      /* We should use an extra table for added functions. */
  188.      { (UNCH *)"TAB",  TABCHAR },
  189.      { NULL,           0 }
  190. };
  191. struct map mstab[] = {        /* Marked section keywords. */
  192.      { key[KTEMP],    MSTEMP  },
  193.      { key[KINCLUDE], MSTEMP  }, /* Treat INCLUDE like TEMP; both are NOPs.*/
  194.      { key[KRCDATA],  MSRCDATA},
  195.      { key[KCDATA],   MSCDATA },
  196.      { key[KIGNORE],  MSIGNORE},
  197.      { NULL,          0 }
  198. };
  199. struct map pubcltab[] = {     /* Names for public text class. */
  200.      { (UNCH *)"CAPACITY",  FPICAP  },
  201.      { (UNCH *)"CHARSET",   FPICHARS},
  202.      { (UNCH *)"DOCUMENT",  FPIDOC  },
  203.      { (UNCH *)"DTD",       FPIDTD  },
  204.      { (UNCH *)"ELEMENTS",  FPIELEM },
  205.      { (UNCH *)"ENTITIES",  FPIENT  },
  206.      { (UNCH *)"LPD",       FPILPD  },
  207.      { (UNCH *)"NONSGML",   FPINON  },
  208.      { (UNCH *)"NOTATION",  FPINOT  },
  209.      { (UNCH *)"SHORTREF",  FPISHORT},
  210.      { (UNCH *)"SUBDOC",    FPISUB  },
  211.      { (UNCH *)"SYNTAX",    FPISYN  },
  212.      { (UNCH *)"TEXT",      FPITEXT },
  213.      { NULL,            0 }
  214. };
  215. UNCH indefent[] = "\12#DEFAULT";   /* Internal name: default entity name. */
  216. UNCH indefetd[] = "\12*DOCTYPE";   /* Internal name: default document type. */
  217. UNCH indocent[] = "\12*SGMLDOC";   /* Internal name: SGML document entity. */
  218. UNCH indocetd[]  = "\6*DOC";       /* Internal name: document level etd. */
  219. UNCH indtdent[]  = "\11*DTDENT";   /* Internal name: external DTD entity. */
  220.  
  221. struct etd dumetd[3];
  222. struct entity *dumpecb;
  223. UNCH sgmlkey[] = "SGML";
  224.